package com.ycp.erp.warehouse.ui.binder;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.one.common.view.multitytype.adapter.BaseItemBinder;
import com.one.common.view.multitytype.adapter.BaseViewHolderMulti;
import com.ycp.erp.R;
import com.ycp.erp.warehouse.model.bean.Warehouse;
import com.ycp.erp.warehouse.ui.inter.WarehouseListener;

import androidx.annotation.NonNull;

/**
 * Class Des:
 * Created by bjh on 2021/8/24.
 */
public class WarehouseBinder extends BaseItemBinder<Warehouse> {
    public WarehouseBinder() {
        super(R.layout.item_warehouse_manager);
    }

    @Override
    protected void bindView(@NonNull BaseViewHolderMulti holder, Warehouse item) {
        ImageView ivSelect = holder.getView(R.id.ivSelect);
        View rlItem = holder.getView(R.id.rlItem);
        if (item.isSelect()) {
            ivSelect.setImageResource(R.mipmap.ic_selected_circle);
        } else {
            ivSelect.setImageResource(R.mipmap.ic_unselected_circle);
        }
        rlItem.setOnClickListener(v -> {
            item.setSelect(!item.isSelect());
            if (item.isSelect()) {
                if (this.warehouseListener!=null){
                    this.warehouseListener.onSelect(item);
                }
                ivSelect.setImageResource(R.mipmap.ic_selected_circle);
            } else {
                ivSelect.setImageResource(R.mipmap.ic_unselected_circle);
            }
        });
        holder.setText(R.id.tvName,item.getWarehouseName());
    }
    WarehouseListener warehouseListener;
    public void  setWarehouseListener(WarehouseListener warehouseListener){
        this.warehouseListener=warehouseListener;
    }
}
